package com.yidu.best.systemManagement.userControl.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.yidu.best.systemManagement.userControl.domain.User;
import com.yidu.best.systemManagement.userControl.service.UserService;



@Controller
@RequestMapping("/sys/")
public class LoginController {
	@Autowired
	private UserService userService;
	
	
	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	@RequestMapping(value="toLogin",method=RequestMethod.GET)
	public String tologin(){
		return "login";
		
	}
	
	/**
	 * 用户登陆
	 */
	@RequestMapping(value="login",method=RequestMethod.POST)
	public String doLogin(String userName,String password,HttpServletRequest req){
		User user=userService.login(userName, password);
		req.setAttribute("user", user);
		if(user!=null){
			return "index";
		}else{
			return "../../login";
		}
		
	}
}
